﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BattleCore;
using BattleCore.Events;
using PsyModules;

namespace Battle
{
    public class ShipControl
    {
        ShortChat msg = new ShortChat();
        public class SPlayer
        {
            private string _PlayerName;
            public string PlayerName
            {
                get { return _PlayerName; }
                set { _PlayerName = value; }
            }

            private ShipTypes _NewShip = ShipTypes.Spectator;
            public ShipTypes NewShip
            {
                get { return _NewShip; }
                set { _NewShip = value; }
            }

            private ShipTypes _OldShip = ShipTypes.Spectator;
            public ShipTypes OldShip
            {
                get { return _OldShip; }
                set { _OldShip = value; }
            }
        }

        List<SPlayer> ShipList = new List<SPlayer>();

        public void PlayerEntered(string PlayerName)
        {
            SPlayer newS = new SPlayer();
            newS.PlayerName = PlayerName;
            ShipList.Add(newS);
        }

        public void ShipChange(ShipChangeEvent s)
        {
            SPlayer s_player = GetPlayer(s.PlayerName);

            if (s.ShipType.ToString() == "255")
                s.ShipType = s_player.NewShip;
            else if (s.PreviousShipType.ToString() == "255")
                s.PreviousShipType = s_player.NewShip;

            s_player.NewShip = s.ShipType;
            s_player.OldShip = s.PreviousShipType;
        }

        public SPlayer GetPlayer(string PlayerName)
        {
            SPlayer reply = new SPlayer();

            ShipList.ForEach(delegate(SPlayer s)
            {
                if (s.PlayerName == PlayerName)
                    reply = s;
            });

            return reply;
        }
    }
}
